package meng.study;

import meng.study.annotation.MyAnnotation;
import meng.study.model.Person;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @describe: 类描述信息
 * @author: morningcat.zhang
 * @date: 2019/4/17 2:25 PM
 */
public class AnnotationTest {
    public static void main(String[] args) throws ClassNotFoundException {
        Class<Person> personClass = Person.class;

        Method[] methods = personClass.getMethods();
        // 查找方法上的MyAnnotation注解
        for (Method method : methods) {
            // System.out.println(method.getName());
            boolean flag = method.isAnnotationPresent(MyAnnotation.class);
            if (flag) {
                MyAnnotation mya = method.getAnnotation(MyAnnotation.class);
                System.out.println(mya.value());
                System.out.println(mya.num());
            }
        }

        System.out.println("---------------------------");
        for (Method method : methods) {
            Annotation[] annotations = method.getAnnotations();
            for (Annotation annotation : annotations) {
                if (annotation instanceof MyAnnotation) {
                    System.out.println(((MyAnnotation) annotation).value());
                    System.out.println(((MyAnnotation) annotation).num());
                }

            }
        }
    }
}
